package com.aramis.mydytt.ui.bean

import com.aramis.mydytt.db.DownloadedMovieBean
import com.aramis.mydytt.db.FavoriteMovieBean
import java.io.Serializable

/**
 * Description: beans
 * @author lizhidan
 * Created: 2021/4/6
 */

data class DataWrapper<T>(val code: Int, val msg: String?, val data: T?) : Serializable {
    companion object {
        private const val CODE_SUCCESS = 1
    }

    fun success(): Boolean = code == CODE_SUCCESS

    fun dataNotNull(): Boolean {
        return success() && data != null
    }
}

//电影列表容器
data class MovieItemWrapperBean(
    var title: String? = null,
    var video: List<MovieItemBean>? = null,
    var tagId: Int = -1
) : Serializable

//电影列表item
data class MovieItemBean(
    val id: String, val title: String, val path: String, val score: String?,
    val playlist: MovieItemPlayListBean?, val definition: Int, var playSubTitle: String? = null,
    var selected: Boolean = false
) : Serializable {
    companion object {
        const val definition_HD = 1//高清
        const val definition_MD = 2//标清
        const val definition_HOT = 3//热门
    }

    fun toFavoriteMovieBean(): FavoriteMovieBean {
        val favoriteMovieBean = FavoriteMovieBean()
        favoriteMovieBean.movieId = id
        favoriteMovieBean.title = title
        favoriteMovieBean.createTime = System.currentTimeMillis()
        favoriteMovieBean.path = path
        favoriteMovieBean.score = score
        favoriteMovieBean.playSubTitle = playlist?.title
        return favoriteMovieBean
    }

    fun toDownloadedMovieBean(): DownloadedMovieBean {
        val downloadedMovieBean = DownloadedMovieBean()
        downloadedMovieBean.movieId = id
        downloadedMovieBean.title = title
        downloadedMovieBean.createTime = System.currentTimeMillis()
        downloadedMovieBean.path = path
        downloadedMovieBean.score = score
        downloadedMovieBean.playSubTitle = playlist?.title
        return downloadedMovieBean
    }
}

data class MovieItemPlayListBean(val title: String?) : Serializable

//电影标签
data class MovieTagBean(val id: Int, val name: String) : Serializable

//电影属性，搜索用
data class MovieField(val fieldName: String, val fieldId: Int, val fieldValueStr: String? = null) : Serializable {

    companion object {
        const val CATE_MOVIE = 1//电影
        const val CATE_SERIES = 2//电视剧
        private const val STYLE_CATE = 0
        private const val STYLE_AREA = 1
        private const val STYLE_YEAR = 2
        private const val STYLE_TYPE = 3
        private const val STYLE_SORT = 4

        const val SORT_HOT = "hot"

        fun emptyField(): MovieField {
            return MovieField("", -1)
        }

        fun getFiledList(style: Int): List<MovieField>? {
            return when (style) {
                STYLE_CATE -> {
                    getCateMovieFieldList()
                }
                STYLE_AREA -> {
                    getAreaMovieFieldList()
                }
                STYLE_YEAR -> {
                    getYearMovieFieldList()
                }
                STYLE_TYPE -> {
                    getTypeMovieFieldList()
                }
                STYLE_SORT -> {
                    getSortMovieFieldList()
                }
                else -> null
            }
        }

        //电影分类标签列表
        private fun getCateMovieFieldList(): List<MovieField> {
            return listOf(
                MovieField("全部分类", 0),
                MovieField("电影", CATE_MOVIE),
                MovieField("电视剧", CATE_SERIES),
                MovieField("动漫", 3)
            )
        }

        //电影地区标签列表
        private fun getAreaMovieFieldList(): List<MovieField> {
            return listOf(
                MovieField("全部地区", 0),
                MovieField("国产", 1),
                MovieField("中国香港", 3),
                MovieField("中国台湾", 6),
                MovieField("美国", 5),
                MovieField("韩国", 18),
                MovieField("日本", 2),
            )
        }

        //电影年份标签列表
        private fun getYearMovieFieldList(): List<MovieField> {
            return listOf(
                MovieField("全部年份", 0),
                MovieField("2020", 16),
                MovieField("2019", 7),
                MovieField("2018", 2),
                MovieField("2017", 3),
                MovieField("2016", 22)
            )
        }

        //电影类型标签列表
        private fun getTypeMovieFieldList(): List<MovieField> {
            return listOf(
                MovieField("全部类型", 0),
                MovieField("剧情", 1),
                MovieField("爱情", 2),
                MovieField("动画", 3),
                MovieField("喜剧", 4),
                MovieField("战争", 5),
                MovieField("歌舞", 6),
                MovieField("古装", 7),
                MovieField("奇幻", 8),
                MovieField("冒险", 9),
                MovieField("动作", 10),
                MovieField("科幻", 11),
                MovieField("悬疑", 12),
                MovieField("犯罪", 13),
                MovieField("家庭", 14),
                MovieField("传记", 15),
                MovieField("运动", 16),
                MovieField("同性", 17),
                MovieField("惊悚", 18),
                MovieField("短片", 20)
            )
        }

        //电影排序标签列表
        private fun getSortMovieFieldList(): List<MovieField> {
            return listOf(
                MovieField("热门", 0, SORT_HOT),
                MovieField("最新", 0, "update"),
                MovieField("评分", 0, "rating")
            )
        }
    }
}

//电影详情
data class MovieDetailBean(
    val id: String,
    val title: String,
    val score: String?,
    val description: String?,
    val original_name: String?,
    val duration: String?,
    val episodes_count: String?,
    val episode_duration: String?,
    val imdb_url: String?,
    val year: MovieDetailYearBean?,
    val area: MovieDetailAreaBean?,
    val shared: String?,
    val thumbnail: String?,
    val languages: List<MovieDetailLanguagesBean>?,
    val types: List<MovieDetailTypesBean>?,
    val tags: List<MovieDetailTagsBean>?,
    val directors: List<MovieDetailNameBean>?,
    val writers: List<MovieDetailNameBean>?,
    val actors: List<MovieDetailNameBean>?,
    val category: List<MovieDetailCategoryBean>?,
    val btbo_downlist: List<MovieDetailDownListBean>?,
    val xunlei_downlist: List<MovieDetailXunleiDownListBean>?,
    val update_cycle: String?
) : Serializable {

    fun toFavoriteMovieBean(): FavoriteMovieBean {
        val favoriteMovieBean = FavoriteMovieBean()
        favoriteMovieBean.movieId = id
        favoriteMovieBean.title = title
        favoriteMovieBean.createTime = System.currentTimeMillis()
        favoriteMovieBean.path = thumbnail
        favoriteMovieBean.score = score
        return favoriteMovieBean
    }
}

data class MovieDetailYearBean(val id: String, val title: String) : Serializable
data class MovieDetailAreaBean(val id: String, val title: String) : Serializable
data class MovieDetailLanguagesBean(val value: String) : Serializable
data class MovieDetailTypesBean(val id: String, val name: String) : Serializable
data class MovieDetailTagsBean(val id: String, val name: String) : Serializable
data class MovieDetailNameBean(val id: String, val name: String?) : Serializable
data class MovieDetailCategoryBean(val id: Int = 0, val title: String) : Serializable
data class MovieDetailDownListBean(val id: Int = 0, val title: String, val url: String?, var fromDytt: Boolean = false) :
    Serializable

data class MovieDetailXunleiDownListBean(val id: String, val title: String, val url: String?) : Serializable

//电影详情-评论
data class MovieCommentBean(
    val id: String, val content: String?, val thumb_num: Int = 0, val time: String?, val nickname: String?, val avatar: String?,
    val have_thumbed: Boolean = false
) : Serializable

//电影专题
data class MovieSpecialBean(val cover: String, val id: Int, val title: String) : Serializable

//电影专题详情
data class MovieSpecialDetailBean(
    val content: String?, val cover: String, val id: Int, val title: String,
    val video: List<MovieSpecialDetailItemBean>?
) : Serializable

//电影专题详情item
data class MovieSpecialDetailItemBean(
    val content: String?, val id: Int, val title: String,
    val definition: Int, val path: String?, val score: String?
) : Serializable {

    fun toMovieItemBean(): MovieItemBean {
        return MovieItemBean(id.toString(), title, path ?: "", score, null, 0)
    }
}

//电影搜索结果
data class MovieSearchBean(
    val cate_id: Int, val definition: Int, val id: Int, val mask: String?,
    val score: String?, val thumbnail: String?, val title: String?
) : Serializable {

    fun toMovieItemBean(): MovieItemBean {
        return MovieItemBean(id.toString(), title ?: "", thumbnail ?: "", score, MovieItemPlayListBean(mask), definition)
    }
}

